<?php

/**
 * @author aisyah,freaksmj
 * @copyright 2012
 */
 
require_once "../dao/user_dao.php";
require_once "../../config/paging.php";

include_once "header.php";

$modul=$_GET['modul'];
$id=$_GET['id'];
$breadcrump ="";

echo "<div class='container'>
<div class='row'>";

switch($modul){
    
    default :
	
		$p = new Paging;
        $batas = 10;
        $posisi = $p->cari_posisi($batas);
		
        echo "
            
            <table class='table table-bordered'>
                <tr><td colspan=6><a href='user_view.php?modul=tambah'><image src='../images/add.png'></a></td></tr>
                <th>ID</th><th>NAMA USER</th><th>KATEGORI USER</th><th>LAST_LOGIN</th><th>AKSI</th>
                ";
				
        $user = new User_Dao($class_db);
        
        $user->get_user(null,$posisi,$batas);
        
        //$jmldata = count($user->user);
        
        $data = $user->user;
        
        if($data!=null) {
            
           foreach($data as $userr) {            
            
            $user->db->hasil = "";
			$user->db->show_Data('user_categories','category',null,null,'usercat_id='.$userr->category);
			$hasil = $user->db->hasil;
			
			foreach($hasil as $user_categories){
				$user_categories = $user_categories['category'];
			}
			
			echo "
                <tr valign = top>
                    <td>$userr->user_id</td>
                    <td><a href='user_view.php?modul=detil&id=$userr->user_id'>$userr->username</a></td> 
                    <td>$user_categories</td>                   
                    <td>$userr->last_login</td>                    
                    <td><a href='user_view.php?modul=ubah&id=$userr->user_id'><image src='../images/edit.gif'></a> | 
                        <a href='user_aksi.php?modul=hapus&id=$userr->user_id'><image src='../images/delete.gif'></a></td>
                </tr>
                ";        
            
            } 
        }else{
            echo "<tr><td colspan=5 align=center>DATA TIDAK DITEMUKAN</td></tr>";
        }
        
        //print_r($data);        {
        
        
        
         
        echo "            
            </table>
            ";
    break;    
    
    case "ubah":
    
        $user = new User_Dao($class_db);       
        
        $user->get_user($id);
        
        $userr = $user->user;    
        
        foreach($userr as $data) {
        
        echo "
            <form method='POST' action='user_aksi.php?modul=ubah' enctype='multipart/formdata'>
            <input type='hidden' name='id' value=$data->user_id>
            <table>
                <tr><td colspan=8 align='center'><h1>Ubah Data User</h1></td></tr>
					<tr><td>Nama User</td><td><input type='text' name='username' value='$data->username'></td></tr>
					<tr><td>Password</td><td><input type='text' name='password' value='$data->password'</td></tr>
					<tr><td>Kategori User</td><td><input type='text' name='category' value='$data->category'></td></tr>
                    <tr><td>Login Terakhir</td><td><input type='text' name='last_login' value='$data->last_login' readonly=readonly></td></tr>                                 
                    <tr><td colspan=2><input class='btn btn-primary' type=submit value=Simpan><input class='btn btn-primary' type=button value=Batal onclick=self.history.back()></td></tr>
				</table>
            </form>
            ";
            
            }
    
    break;
    
    case "detil":
    
        $user = new User_Dao($class_db);
        
        $user->get_user($id);
        
        $userr = $user->user;
        
        foreach($userr as $data) {
            
            echo "
            <table>
                <tr><td colspan=8 align='center'><h1>Data Produk</h1></td></tr>
					<tr><td>Nama User</td><td>$data->username</td></tr>
					<tr><td>Kategori User</td><td>$data->category</td></tr>					
                    <tr><td>Login Terakhir</td><td>$data->last_login</td></tr>                                  
                    <tr><td colspan=2><input type=button class=btn value='UBAH' onclick=\"window.location.href='user_view.php?modul=ubah&id=$data->user_id';\">
                    <input class='btn' type=button value=Kembali onclick=self.history.back()></td></tr>
				</table>
            ";
            
            }
    
    break;
  
echo "</div></div>";  
    
}